<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-11
 * Time: 13:32
 */

namespace app\service;


use EasyWeChat\Kernel\Messages\Image;
use EasyWeChat\Kernel\Messages\Music;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\Text;
use EasyWeChat\Kernel\Messages\Video;

class WechatService extends ThirdService
{
    public static $msgType_text=1; //文本
    public static $msgType_news=2; //图文
    public static $msgType_img=3; //图片
    public static $msgType_video=4; //视频
    public static $msgType_article=5; //文章
    public static $msgType_music=6; //音乐

    public function __countruct ($option=false) {
        parent::__countruct($option);
    }

    //发送客服消息
    public  function send($msg_type,$openid,$content){

        switch ($msg_type){
            case self::$msgType_text:  //文本消息
                $message = new Text($content);
                break;
            case self::$msgType_news: //图文消息
                $message = new News($content);
                break;
            case self::$msgType_img:  //图片消息
                $message = new Image($content);
                break;
            case self::$msgType_video:  //视频消息
                $message = new Video($content);
                break;
            case self::$msgType_music: //音频消息
                $message = new Music($content);
                break;
            default:
                $message = new Text($content);
                break;
        }
        $result = $this->officialAccount->customer_service->message($message)->to($openid)->send();
        /*if($msg_type==self::$msgType_news){
            LogService::S()->writeLog('st','kefu',$result);
        }*/
        return $result;
    }

    /* 上传图片素材 */
    public function uploadImage ($path) {
        return $this->officialAccount->media->uploadImage($path);
    }

}